<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
    <title>Auction Site</title>
</head>

<body>
	<a href ='/home/'>Home</a>
	<a href ='/create/'>Create auction</a>
	<a style="color:red;">{{msg}}</a>
{#    This form is shown only if the user is not logged in by verifying if the looged_in has a data or not#}
    {% if not logged_in %}
	<form method = "POST" action="/login/">
	{% csrf_token %}
		<p>Username: <input type="text" name="username"></p>
		<p>Password: <input type="password" name="password"></p>
		<INPUT TYPE=HIDDEN NAME="nextto" VALUE="/item/{{auc.id}}/">
		<input type="submit" value="Submit">
		<label>Don't have an account? <a href = '/adduser/'>Click here</a></label>
	</form>
    {% else %}
      <form method = "POST" action="/logout/">
      {% csrf_token %}
		<INPUT TYPE=HIDDEN NAME="nextto" VALUE="/item/{{auc.id}}/">
        <input type="submit" value="Logout">
      </form>
	{% endif %}
{#    This will show only if the user wand to edit the page and it can be accessed only by the logged in user.#}
    {% if item_edit == "edit" %}
            <form method = "POST">
            {% csrf_token %}<br>
            <label>Title</label>
            <p>{{ auc.title }}</p>
            <label>Category</label>
            <p>{{ auc.category }}</p>
            <label>Current Price</label>
            <p>{{ auc.cPrice }}</p>
            <label>Description</label>
{#            User can change only description of an item #}
            {% if not status  %}
            <input type="text" name="i_desc"  cols="80" rows="30" value="{{ auc.iDesc }}" /><br>
            {% else  %}
                <p>{{ auc.iDesc }}</p>
            {% endif %}
            <label>Start Date</label>
            <p>{{ auc.sDate }}</p>
            <label>End Date</label>
            <p>{{ auc.eDate }}</p>
            <label>Auction Owner</label>
            <p>{{ auc.aOwner }}</p>

            <h2>Bidders for this item</h2>
            {% if not biderList %}
                <p>This item has no bidder yet.</p>
            {% endif %}
            {% for bid in biderList %}
                    <p>{{ bid.bider }}</p>
            {% endfor %}
            {% if not status  %}
            <input type="hidden" name="edited_version" value="{{ edited_version }}" />
            <input type="submit" value="Save">
            {% endif %}
            </form>
{#    This will be show only if the user want to see the item details and want to increase the bid.#}
{#     It can be accessed by any user weather he is logged in or not#}
    {% elif item_edit == "item" %}
            <h2>Title</h2>
            <p>{{ auc.title }}</p>
            <h2>Category</h2>
            <p>{{ auc.category }}</p>
            <h2>Current Price</h2>
{#            This is shown only if the conflict occurs meaning other user has done the modificaion before you.#}
            {% if conflict %}
                    <p style="color:red;">{{ conflict }}</p>
            {% endif %}
{#            This will checks if the bid amount was valid or not.#}
            {% if bid_invalid %}
                    <p style="color:red;">{{ bid_invalid }}</p>
            {% endif %}
{#            This wil check if the bid user is now an owner of the auction#}
            {% if bid_user  %}
                {% if not status  %}
                    <form method = "POST">
                    {% csrf_token %}
                        <input type="number" step="any"  name="c_price" value="{{ c_price }}" />
                        <input type="hidden" name="edited_version" value="{{ edited_version }}" />
                        <input type="submit" value="Increase Bid">
                    </form>
               {% endif %}
{#            This is shown if the bid user is the owner of the auction meaning he can not bid on his own item#}
            {% else %}
                <p>{{ c_price }}</p>
            {% endif %}
            <h2>Item Description</h2>
            <p>{{ auc.iDesc }}</p>
            <h2>Start Date</h2>
            <p>{{ auc.sDate }}</p>
            <h2>End Date</h2>
            <p>{{ auc.eDate }}</p>
            <h2>Auction Owner</h2>
            <p>{{ auc.aOwner }}</p>

            <h3>Biders for this Item</h3>
{#            This will be shown if there is no valid bidders#}
            {% if not biderList %}
                <p style="color:red;">This item has no bidder yet.</p>
            {% endif %}
{#            This will shows the list of bidders for the item#}
            {% for bid in biderList %}
                    <p>{{ bid.bider }}</p>
            {% endfor %}
{#            This will be shown if the user is not logged in.#}
            {% if not logged_in %}
                <p style="color:blue;">Log In to bid on this item.</p>
{#            This will be shown if the user is logged in.#}
            {% else %}
{#                Checks if the bidder is the owner of the auction of nor#}
                {% if bid_user %}
                    <p>Bid on this Item.</p>
{#                If he is the owner it will display the following masseage#}
                {% else %}
                    {% if winning %}
                        <p style="color:red;">Since you are Winning this product you cant bid.</p>
                     {% else %}
                       <p style="color:red;">Since you are the owner you can't bid on this item.</p>
                     {% endif %}

                {% endif %}
            {% endif %}
    {% endif %}
</body>
</html>